<?php
/**
 * Created by PhpStorm.
 * User: Tsang
 * Date: 2017/9/24 16:20
 *
 */

namespace app\pc\model;
use think\Model;

class Article extends Model
{
    /**
    *   获取导航id
    */
    public function get_nav_id($name)
    {
        $id = db('admin_nav')->where(['name'=>$name])->value('id');

        if(empty($id))return false;
        return $id;
    }

    /**
    *   获取导航下面的分类id
    */
    public function get_nav_category($nav_id,$id){
        if(!empty($nav_id))$where['nav_id'] = $nav_id;
        if(!empty($id))$where['pid'] = $id;
        $article_category = db('article_category')->where($where)->select();
        $list = [];
        foreach ($article_category as $key => $value) {
            if ($value['pid'] == $id){
                $value['son'] = $this->get_nav_category($nav_id,$value['id']);
                $list[] = $value;
            }
        }
        return $list;
    }
    
    public function detail($id)
    {
        if(!empty($id))$where['id'] = $id;
        $article_info = db('article')->where($where)->find();
        return $article_info;
    }
}